home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 12 - 1996 / 12.12 Dec 96 / Custom AppMaker 2 / AM Code / CMain.cp < prev    next >
Encoding:
Text File  |  1996-03-20  |  3.1 KB  |  178 lines  |  [TEXT/CWIE]

  1. // CMain.cp -- window methods
  2. // Created 20/3/96 12:28 by AppMaker
  3.  
  4. #include "CMain.h"
  5.  
  6. #include <UReanimator.h>
  7. #include <URegistrar.h>
  8. #include <LStream.h>
  9. #include <LStdControl.h>
  10. #include "CSoundAttachment.h"
  11. #include "CSoundsDemoData.h"
  12. #include "CmdCodes.h"
  13.  
  14. #define PPob_MainID    200
  15. #define RidL_MainID    200
  16.  
  17. Boolean        CMain::sIsRegistered = false;
  18.  
  19. //----------
  20. void
  21. CMain::RegisterClass ()
  22. {
  23.     URegistrar::RegisterClass ('Main', (ClassCreatorFunc)CMain::CreateMainStream);
  24.  
  25.     // register the pane classes we use
  26.  
  27.     sIsRegistered = true;
  28. }
  29.  
  30. //----------
  31. CMain*
  32. CMain::CreateMain(
  33.     LCommander            *inSuperCommander,
  34.     CSoundsDemoData        *inData)
  35. {
  36.     if (!sIsRegistered) {
  37.         RegisterClass ();
  38.     }
  39.  
  40.     CMain        *window;
  41.  
  42.     window = (CMain *)LWindow::CreateWindow(PPob_MainID, inSuperCommander);
  43.     window->ConnectToData (inData);
  44.  
  45.     return window;
  46. }
  47.  
  48. //----------
  49. //    This is the function you register with URegistrar to create a
  50. //    CMain from a resource
  51.  
  52. CMain*
  53. CMain::CreateMainStream(
  54.     LStream    *inStream)
  55. {
  56.     return (new CMain(inStream));
  57. }
  58.  
  59. //----------
  60. CMain::CMain()
  61. {
  62. }
  63.  
  64. //----------
  65. CMain::CMain(
  66.     LStream    *inStream)
  67.         : LWindow(inStream)
  68. {
  69. }
  70.  
  71. //----------
  72. CMain::~CMain()
  73. {
  74. }
  75.  
  76. //----------
  77. //    This member function gets called once the containment hierarchy that contains
  78. //    this pane has been built. It gives us a chance to get data members for
  79. //    interesting subviews, and to do other operations now that our subviews exist.
  80. void
  81. CMain::FinishCreateSelf()
  82. {
  83.     mPlayButton = (LStdButton *)FindPaneByID ('Play');
  84.      mPlayButton->AddAttachment(new CSoundAttachment("Click", msg_Click));
  85.  
  86.     UReanimator::LinkListenerToControls(this, this, RidL_MainID);
  87.         // the purpose is to "connect" self to whatever controls
  88.         // that we want to "listen" to
  89.  
  90. // any additional initialization for your window:
  91.  
  92. }
  93.  
  94. //----------
  95. void
  96. CMain::ConnectToData    (CSoundsDemoData        *inData)
  97. {
  98.     mData = inData;
  99.     inData->AddListener (this);
  100. }
  101.  
  102. //----------
  103. void
  104. CMain::ListenToMessage(
  105.     MessageT    inMessage,
  106.     void        *ioParam)
  107. {
  108.     switch (inMessage) {
  109.  
  110.     default:
  111.         break;
  112.     }
  113. }
  114.  
  115. //----------
  116. Boolean
  117. CMain::ObeyCommand(
  118.     CommandT    inCommand,
  119.     void        *ioParam)
  120. {
  121.     Boolean        cmdHandled = true;
  122.  
  123.     switch (inCommand) {
  124.  
  125.     // +++ Add cases here for the commands you handle
  126.     //        Remember to add same cases to FindCommandStatus below
  127.     //        to enable/disable the commands
  128.  
  129.     default:
  130.             cmdHandled = LWindow::ObeyCommand(inCommand, ioParam);
  131.         break;
  132.     }
  133.  
  134.     return cmdHandled;
  135. }
  136.  
  137. //----------
  138. void
  139. CMain::FindCommandStatus(
  140.     CommandT    inCommand,
  141.     Boolean        &outEnabled,
  142.     Boolean        &outUsesMark,
  143.     Char16        &outMark,
  144.     Str255        outName)
  145. {
  146.     outUsesMark = false;
  147.  
  148.     switch (inCommand) {
  149.  
  150.     // +++ Add cases here for the commands you handle
  151.  
  152.     default:
  153.             LWindow::FindCommandStatus(inCommand, outEnabled,
  154.                                         outUsesMark, outMark, outName);
  155.         break;
  156.     }
  157. }
  158.  
  159. //----------
  160. Boolean
  161. CMain::FocusDraw()
  162. {
  163.     Boolean        focused = LView::FocusDraw();
  164.  
  165.     if (focused) {
  166.         AuxWinHandle    awHndl;
  167.         CTabHandle        awCTable;
  168.         ColorSpec        contentSpec;
  169.  
  170.         GetAuxWin(GetMacPort(), &awHndl);
  171.         awCTable = (**awHndl).awCTable;
  172.         contentSpec = (**awCTable).ctTable [wContentColor];        // should search vs. index
  173.         ::RGBBackColor(&contentSpec.rgb);
  174.     }
  175.  
  176.     return focused;
  177. }
  178.